package com.mijie.homi.ns.dao;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.mijie.core.IBatisDao;
import com.mijie.homi.common.domain.user.DeviceInfo;
import com.mijie.homi.common.domain.user.Setting;
import com.mijie.homi.common.domain.user.ThirdPartAccount;
import com.mijie.homi.common.domain.user.User;
import com.mijie.homi.common.domain.user.UserExtInfo;

@Repository
public class UserDao extends IBatisDao{

	public DeviceInfo getDeviceInfo(String deviceId){
		return this.selectOne("getDeviceInfo", deviceId);
	}
	
	public int resetDeviceUnreadNotifyCount(String deviceId){
		return this.update("resetDeviceUnreadNotifyCount",deviceId);
	}
	
	public User getUserById(int id){
		return this.selectOne("getUserById", id);
	}
	
	public List<User> listUserByNicknameAndPassword(String nickName,String passwd){
		Map<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("nickName", nickName);
		parameter.put("passwd", passwd);
		return this.selectList("listUserByNicknameAndPassword", parameter);
	}
	
	public User getUserByEmail(String email){
		return this.selectOne("getUserByEmail", email);
	}
	
	public int deleteUserInfoSubcribe(int subscriber){
		return this.delete("deleteUserInfoSubcribe", subscriber);
	}
	
	public UserExtInfo getUserExtInfoByUserId(int userId){
		return this.selectOne("getUserExtInfoByUserId",userId);
	}
	
	public int updateLastLoginAt(int id,String os,String clientIP){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("id", id);
		parameter.put("os", os);
		parameter.put("clientIP", clientIP);
		parameter.put("lastLoginAt", new Date());
		return this.update("updateLastLoginAt", parameter);
	}
	
	public int incrOnlineLong(int id,int onlineLong,int online){
		HashMap<String,Object> parameter = new HashMap<String,Object>();
		parameter.put("id", id);
		parameter.put("online", online);
		parameter.put("onlineLong", onlineLong);
		return this.update("incrOnlineLong", parameter);
	}
	
	public List<ThirdPartAccount> listThirdPartAccountByUser(int userId){
		return this.selectList("listThirdPartAccountByUser", userId);
	}
	
	public Setting getSettingByUser(int userId){
		return this.selectOne("getSettingByUser", userId);
	}
}
